package com.zxr.demo.controllers;
import com.zxr.demo.commom.bo.ChatMessage;
import com.zxr.demo.service.ChatService;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chat")
public class ChatController {

    @Autowired
    private ChatService chatService;

    /**
     * 发送消息并获取AI回复
     */
    @PostMapping("/send")
    public ChatMessage sendMessage(
            @RequestHeader("Authorization") String token,
            @RequestBody @NotBlank String content) {
        return chatService.sendMessage(token, content);
    }

    /**
     * 获取历史聊天记录
     */
    @GetMapping("/history")
    public List<ChatMessage> getHistory(
            @RequestHeader("Authorization") String token,
            @RequestParam(required = false) Integer page,
            @RequestParam(required = false) Integer size) {
        return chatService.getHistoryMessages(token, page, size);
    }

    /**
     * 清除聊天记录
     */
    @DeleteMapping("/clear")
    public Boolean clearHistory(@RequestHeader("Authorization") String token) {
        return chatService.clearHistory(token);
    }
}
